import Vue from "vue"
import Vuex from "vuex"

Vue.use(Vuex)

const store = new Vuex.Store({
	//数据源
	state:{
		historyLists:uni.getStorageSync('_historyLists')||[]
	},
	mutations:{
		SET_HISTORY_LISTS(state,history){
			state.historyLists = history
		},
		CLEAR_HISTORY_LISTS(state){
			state.historyLists = []
		}
	},
	actions:{
		set_history({commit,state},history){
			
			let list = state.historyLists
			list.unshift(history)
			uni.setStorageSync('_historyLists',list)
			commit('SET_HISTORY_LISTS',list)
		},
		clear_history({commit}){
			// uni.clearStorageSync('_historyLists',[])
			uni.removeStorageSync('_historyLists')
			commit('CLEAR_HISTORY_LISTS')
		}
	}
})

export default store